/**
 * @return:$
 * @since: 1.0.0
 * @Author:WXX
 * @Date: 2020/8/26$ 8:22$
 */
import request from '../plugins/request'
import { api } from './api'
// import { getToken } from '../libs/utils'


// 登录
export const login = (data) => {
  return postRequest(api.Login,data)
}
// 用户信息
export const getUserInfo = (data) => {
  return postRequest(api.GetUserInfo,data)
}
// 用户信息
export const getUserInfoAuto = (data) => {
  postRequest(api.GetUserInfo,data).then(res => {
    console.log(res)
    if (res.code === 200) {
      localStorage.setItem('overnight_userInfo', JSON.stringify(res.data))
    }
  })
}

// 随行嘉宾信息
export const getGuest = (data) => {
  return postRequest(api.GetGuest,data)
}
export const getGuestAuto = (data) => {
  postRequest(api.GetGuest,data).then(res => {
    console.log(res)
    if (res.code === 200) {
      localStorage.setItem('accompany', JSON.stringify(res.data))
    }
  })
}
// update嘉宾信息
export const updateGuest = (data) => {
  delete data.gmtCreate
  delete data.gmtModified
  delete data.operateIp
  delete data.operatorId
  delete data.operatorName
  delete data.wxOpenId
  if (data.salution === '称谓*') {
    data.salution = ''
  }
  if (data.birthdate === '出生日期*') {
    data.birthdate = ''
  }
  return postRequest(api.UpdateGuest,data)
}

// 行程信息
export const getTravel = (data) => {
  return postRequest(api.GetTravel,data)
}
export const getTravelAuto = (data) => {
  postRequest(api.GetTravel,data).then(res => {
    console.log(res)
    if (res.code === 200) {
      localStorage.setItem('travel', JSON.stringify(res.data))
    }
  })
}
// 行程信息
export const updateTravel = (data) => {
  return postRequest(api.UpdateTravel,data)
}
// 验证邮箱是否存在
export const validEmail = (data) => {
  return postRequest(api.ValidEmail,data)
}
// 注册
export const register = (data) => {
  return postRequest(api.Register,data)
}
// 完善用户信息
export const updateUserInfo = (data) => {
  if (data.salution === 'Salutation*' || data.salution === '称谓*') {
    data.salution = ''
  }
  if (data.mobilePhoneType === '手机类型*' || data.mobilePhoneType === 'Mobile Phone Type*') {
    data.mobilePhoneType = ''
  }
  return postRequest(api.UpdateInfo,data)
}
// 获取邮箱验证码
export const getPhoneCode = (data) => {
  return postRequest(api.GetPhoneCode,data)
}

// 获取个人行程
export const getMyItinerary = (data) => {
  return postRequest(api.MyItinerary,data)
}

// 发送重置密码邮件
export const sendResetPasswordEmail = (data) => {
  return postRequest(api.SendResetEmail,data)
}

// 通过邮件 重置密码
export const resetPasswordByEmail = (data) => {
  return postRequest(api.ResetPassword,data)
}


const postRequest = (url,data={},params={})=>{
  return request({url, data,params, method: 'post'})
}
const getRequest = (url,data={},params={})=>{
  return request({url, data,params, method: 'get'})
}
